
package top.iridescent.model;

import lombok.Data;
import top.iridescent.constant.ResultCode;
import top.iridescent.constant.ResultMsg;

import java.io.Serializable;
import java.util.HashMap;

/**
 * 数据传输对象
 */

@Data
public class Result<T>  implements Serializable {
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    private T data;

    public Result() {
        code = ResultCode.SUCCESS;
        msg = ResultMsg.SUCCESS;
    }
//    public Result<T> put(String key, Object value) {
//        super.put(key, value);
//        return this;
//    }
    public static Result error() {
        return error(ResultCode.FAILURE, ResultMsg.FAILURE);
    }

    public static Result error(String msg) {
        return error(ResultCode.FAILURE, msg);
    }

    public static Result error(int code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result ok(String msg) {
        Result result = new Result();
        result.setMsg(msg);
        return result;
    }


    public static Result ok() {
        return new Result();
    }

    public Result setData(T value) {
        this.data = value;
        return this;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }
}
